﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace WpfApp3
{
    [XmlRoot(IsNullable = false, ElementName = "AutoUpdaterInfo")]
    public class UpdaterModel : ViewModelBase
    {
        public UpdaterModel() { }
        private string version = "";
        /// <summary>
        /// 版本
        /// </summary>
        public string Version
        {
            get { return version; }
            set
            {
                version = value;
                OnPropertyChanged("Version");
            }
        }
        private string force = "";
        /// <summary>
        /// 是否强制升级（1为强制升级）
        /// </summary>
        public string Force
        {
            get { return force; }
            set
            {
                force = value;
                OnPropertyChanged("Force");
            }
        }
        private string application = "";
        /// <summary>
        /// 主程序名称（用于升级完启动）
        /// </summary>
        public string Application
        {
            get { return application; }
            set
            {
                application = value;
                OnPropertyChanged("Application");
            }
        }
        private string url = "";
        /// <summary>
        /// 升级服务器地址
        /// </summary>
        public string Url
        {
            get { return url; }
            set
            {
                url = value;
                OnPropertyChanged("Url");
            }
        }

        private DateTime lastUpdateTime = DateTime.Now;
        /// <summary>
        /// 升级时间
        /// </summary>
        public DateTime LastUpdateTime
        {
            get { return lastUpdateTime; }
            set
            {
                lastUpdateTime = value;
                OnPropertyChanged("LastUpdateTime");
            }
        }

        private string updateInfo = "";
        /// <summary>
        /// 更新信息
        /// </summary>
        public string UpdateInfo
        {
            get { return updateInfo; }
            set
            {
                updateInfo = value;
                OnPropertyChanged("UpdateInfo");
            }
        }

        private ObservableCollection<FileInfo> files = new ObservableCollection<FileInfo>();
        /// <summary>
        /// 更新文件
        /// </summary>
        public ObservableCollection<FileInfo> Files
        {
            get { return files; }
            set
            {
                files = value;
                OnPropertyChanged("Files");
            }
        }
    }

    public class FileInfo : ViewModelBase
    {
        public FileInfo() { }
        private long fSize;
        [XmlAttribute("FSize")]
        public long FSize
        {
            get { return fSize; }
            set
            {
                fSize = value;
                OnPropertyChanged("FSize");
            }
        }

        private string md5 = "";
        [XmlAttribute("Md5")]
        public string Md5
        {
            get { return md5; }
            set
            {
                md5 = value;
                OnPropertyChanged("Md5");
            }
        }

        private string ver = "";
        [XmlAttribute("Ver")]
        public string Ver
        {
            get { return ver; }
            set
            {
                ver = value;
                OnPropertyChanged("Ver");
            }
        }

        private string name = "";
        [XmlAttribute("Name")]
        public string Name
        {
            get { return name; }
            set
            {
                name = value;
                OnPropertyChanged("Name");
            }
        }

    }

}
